const mysql = require('mysql2');

const config = require('./config');
const connections = mysql.createPool({
    host: config.MYSQL_HOST,
    port: config.MYSQL_PROT,
    database: config.MYSQL_DATABASE,
    user: config.MYSQL_USER,
    password: config.MYSQL_PASSWORD
})
connections.getConnection((err, conn) => {
    conn.connect(err => {
        if (err) {
            console.log("连接失败", err)
        } else {
            console.log(`连接数据库成功, 接口访问地址: ${config.APP_HOST}:${config.APP_PORT}`)
        }
    })
})

module.exports = connections.promise();

// APP_HOST=localhost
// APP_PORT=8080

// MYSQL_HOST=8.134.208.162
// MYSQL_PROT=3306
// MYSQL_DATABASE=lawzhuo_blog
// MYSQL_USER=root
// MYSQL_PASSWORD=gupt303NB